<!DOCTYPE html>
<html>
<head>
   <!-- 页面meta -->
   <meta charset="utf-8">
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <title>传智健康</title>
   <meta name="description" content="传智健康">
   <meta name="keywords" content="传智健康">
   <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
   <!-- 引入样式 -->
   <link rel="stylesheet" href="../plugins/elementui/index.css">
   <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
   <link rel="stylesheet" href="../css/style.css">
</head>
<body class="hold-transition">
<div id="app">
   <div class="content-header">
      <h1>健康评估
         <small>中医体质辨识</small>
      </h1>
      <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
         <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
         <el-breadcrumb-item>健康评估</el-breadcrumb-item>
         <el-breadcrumb-item>中医体质辨识</el-breadcrumb-item>
      </el-breadcrumb>
   </div>
   <div class="app-container">
      <div class="box">
         <!--搜索框-->
         <div class="filter-container">
            <el-input placeholder="档案号/姓名" v-model="pagination.queryString" style="width: 200px;"
                      class="filter-item"></el-input>
            <el-button @click="findPage()" class="dalfBut">查询</el-button>
         </div>
         <!--搜索框/-->

         <!--分页数据-->
         <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
            <el-table-column type="index" align="center" label="序号"  min-width="20%"></el-table-column>
            <el-table-column prop="fileNumber" label="档案号" align="center" min-width="45%"></el-table-column>
            <el-table-column prop="name" label="姓名" align="center" min-width="40%"></el-table-column>
            <el-table-column prop="regTime" label="评估日期" align="center" min-width="55%"></el-table-column>

            <el-table-column prop="peaceful" label="平和质" align="center" min-width="40%"></el-table-column>
            <el-table-column prop="qideficiency" label="气虚质" align="center" min-width="40%"></el-table-column>
            <el-table-column prop="yangdeficiency" label="阳虚质" align="center" min-width="40%"></el-table-column>
            <el-table-column prop="yindeficiency" label="阴虚质" align="center" min-width="40%"></el-table-column>
            <el-table-column prop="sputums" label="痰湿质" align="center" min-width="40%"></el-table-column>
            <el-table-column prop="muggy" label="湿热质" align="center" min-width="40%"></el-table-column>
            <el-table-column prop="stasis" label="血瘀质" align="center" min-width="40%"></el-table-column>
            <el-table-column prop="depression" label="气郁质" align="center" min-width="40%"></el-table-column>
            <el-table-column prop="ldiosyncrasy" label="特禀质" align="center" min-width="40%"></el-table-column>
            <el-table-column label="操作" align="center" min-width="115%">
               <template slot-scope="scope">
                  <el-button type="primary" size="mini" @click="handleUpdate(scope.row)" min-width="25%">编辑</el-button>
                  <!--scope.row代表当前行的对象-->
                  <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
               </template>
            </el-table-column>
            <el-table-column label="查看报告" align="center" min-width="50%">
               <template slot-scope="scope">
                     <el-button type="primary" size="mini" @click="handleLook(scope.row)">
                        查看
                     </el-button>
               </template>
            </el-table-column>
         </el-table>
         <!--分页数据/-->

         <!--分页条-->
         <div class="pagination-container">
            <el-pagination
               class="pagiantion"
               @current-change="handleCurrentChange"
               :current-page="pagination.currentPage"
               :page-size="pagination.pageSize"
               layout="total, prev, pager, next, jumper"
               :total="pagination.total">
            </el-pagination>
         </div>
         <!--分页条/-->

         <!-- 编辑标签弹层 -->
         <div class="add-form">
            <el-dialog v-if="dialogFormVisible4Edit" title="编辑体质辨识" :visible.sync="dialogFormVisible4Edit">
               <el-form ref="dataEditForm" :model="formData" label-position="right" label-width="100px">
                  <el-row>
                     <el-col :span="12">
                        <el-form-item label="会员编码">
                           <el-input :disabled="true" v-model="formData.id"/>
                        </el-form-item>
                     </el-col>
                     <el-col :span="12">
                        <el-form-item label="姓名">
                           <el-input :disabled="true" v-model="formData.name"/>
                        </el-form-item>
                     </el-col>
                  </el-row>
                  <el-row>
                     <el-col :span="12">
                        <el-form-item label="平和质">
                           <el-input v-model="formData.peaceful"/>
                        </el-form-item>
                     </el-col>
                     <el-col :span="12">
                        <el-form-item label="气虚质">
                           <el-input v-model="formData.qideficiency"/>
                        </el-form-item>
                     </el-col>
                  </el-row>
                  <el-row>
                     <el-col :span="12">
                        <el-form-item label="阳虚质">
                           <el-input v-model="formData.yangdeficiency"/>
                        </el-form-item>
                     </el-col>
                     <el-col :span="12">
                        <el-form-item label="阴虚质">
                           <el-input v-model="formData.yindeficiency"/>
                        </el-form-item>
                     </el-col>
                  </el-row>
                  <el-row>
                     <el-col :span="12">
                        <el-form-item label="痰湿质">
                           <el-input v-model="formData.sputums"/>
                        </el-form-item>
                     </el-col>
                     <el-col :span="12">
                        <el-form-item label="湿热质">
                           <el-input v-model="formData.muggy"/>
                        </el-form-item>
                     </el-col>
                  </el-row>
                  <el-row>
                     <el-col :span="12">
                        <el-form-item label="血瘀质">
                           <el-input v-model="formData.stasis"/>
                        </el-form-item>
                     </el-col>
                     <el-col :span="12">
                        <el-form-item label="气郁质">
                           <el-input v-model="formData.depression"/>
                        </el-form-item>
                     </el-col>
                  </el-row>
                  <el-row>
                     <el-col :span="12">
                        <el-form-item label="特禀质">
                           <el-input v-model="formData.ldiosyncrasy"/>
                        </el-form-item>
                     </el-col>
                  </el-row>
               </el-form>
               <div slot="footer" class="dialog-footer">
                  <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                  <el-button type="primary" @click="handleEdit()">确定</el-button>
               </div>
            </el-dialog>
         </div>
      </div>
   </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
   var app = new Vue({
      el: '#app',
      data: {
         showDialog: true, //弹框是否为新表单
         pagination: {//分页相关模型数据
            currentPage: 1,//当前页码
            pageSize: 10,//每页显示的记录数
            total: 0,//总记录数
            queryString: null//查询条件
         },
         dataList: [],//当前页要展示的分页列表数据
         formData: {},//表单数据
         dialogFormVisible4Edit: false//编辑表单是否可见
      },

      //钩子函数，VUE对象初始化完成后自动执行,
      created() {
         //初始化分页查询
         this.findPage();
      },

      methods: {
         //编辑
         handleEdit() {
                  //发送ajax请求
                  axios.post("/assessment/add.do",this.formData).then((res)=>{
                     //隐藏表单
                     this.dialogFormVisible4Edit = false;
                     if (res.data.flag) { //添加成功
                        //成功提示框
                        this.$message({
                           message: res.data.message,
                           type: 'success'
                        });
                     } else { //修改失败
                        //失败提示框
                        this.$message.error(res.data.message);
                     }
                  }).finally(()=>{
                     //此处不能重置当前页：用户体验，修改后可以立马定位改的位置
                     //2.2分页查询
                     this.findPage(1); //不重置当前页
                  });
         },

         //分页查询
         findPage(isCustom) {
            //debugger;
            //0.判断是从查询按钮调用此方法
            if (!isCustom) {//无惨:默认重置当前页
               //将当前页码重置为1
               this.pagination.currentPage = 1;
            }
            //console.log("hello findPage!");//测试
            //1.封装参数,当前页,每页尺寸,查询条件
            var para = {
               currentPage: this.pagination.currentPage,
               pageSize: this.pagination.pageSize,
               queryString: this.pagination.queryString
            };
            //2.发送ajax请求
            axios.post("/assessment/findPage.do", para).then(res => {
               //获取返回结果{total:100,rows:[行数据]},赋值给分页模型
               this.pagination.total = res.data.total;
               this.dataList = res.data.rows;//赋值表数据
            });
         },

         // 重置表单
         resetForm() {
            //清除验证信息
            /*if (this.$refs['dataAddForm'] != undefined) {
              this.$refs['dataAddForm'].resetFields();
            }*/
            //清除验证信息
            /*if (this.$refs['dataAddForm'] != undefined) {
              this.$refs['dataAddForm'].clearValidate();
            }*/
            this.formData = {};
         },

          //查看体检报告
          handleLook(row){
             //发送ajax请求，根据会员档案号，获得该会员的体检报告文档名称
              axios.get("/assessment/getFileName/"+row.fileNumber+".do").then((res) => {
                 if (res.data.flag){
                     location.href = "http://q9e6jnrsu.bkt.clouddn.com/"+res.data.data;
                 } else {
                     this.$message.error(res.data.message);
                 }
              });
   },

         // 弹出编辑窗口
         handleUpdate(row) {
             //不使用row直接回显,可能其他管理员已经删除了此条数据,故以数据库为准
            //1.设置显示编辑窗口
            this.dialogFormVisible4Edit = true;

            //2.发送ajax,回显数据
            axios.get("/assessment/getMember/" + row.fileNumber + ".do").then((res) => {
               if (res.data.flag) {//查询成功
                  //设置回显数据
                  this.formData = res.data.data;
               } else {//回显失败原因:多线程同时操作,页面数据已经不存在,故无法回显
                  this.$message.error(res.data.message);
               }
            }).catch().finally();
         },

         //切换页码
         handleCurrentChange(currentPage) {
             //当前页更改时回调函数
            //currentPage为新的当前页
            //1.修改当前页数据
            this.pagination.currentPage = currentPage;
            //2.调用分页查询方法
            this.findPage(1); //使用自定义当前页
         },

         // 删除
         handleDelete(row) {//row为当前行json对象

            //确认框
            this.$confirm('确认删除吗?', '提示', {
               confirmButtonText: '确定',
               cancelButtonText: '取消',
               type: 'warning'
            }).then(() => {//点确认,回调
               //发送ajax请求
               axios.delete("/assessment/delete/" + row.fileNumber + ".do").then((res) => {
                  //判断是否删除成功
                  if (res.data.flag) {//删除成功
                     //成功框
                     app.$message({
                        message: res.data.message,
                        type: 'success'
                     });

                  } else {//删除失败
                     //失败框
                     this.$message.error(res.data.message);
                  }
               }).finally(() => {//始终执行
                  this.findPage(1);//调用分页查询
               });
            }).catch(() => {//点取消,回调
               //取消框
               this.$message({
                  type: 'info',
                  message: '已取消操作'
               });
            });
         }

      }
   });
</script>

</html>